package com.anjubao.parking.municipal.parkinglot.service;

import com.anjubao.parking.municipal.parkinglot.dto.DeviceLogDto;
import com.anjubao.parking.municipal.parkinglot.dto.VideoPileDto;
import com.anjubao.parking.municipal.parkinglot.mapper.ParkingLotDeviceLogMapper;
import com.anjubao.parking.municipal.parkinglot.mapper.ParkingLotDeviceVideoPileMapper;
import com.anjubao.parking.municipal.parkinglot.model.ParkingLotDeviceLog;
import com.anjubao.parking.municipal.parkinglot.util.FormTransfer;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * 设备日志服务
 * 
 * @author anjubao
 *
 */
@Service
@Slf4j
public class ParkingLotDeviceLogService extends ServiceImpl<ParkingLotDeviceLogMapper,ParkingLotDeviceLog> {

    @Autowired
    private ParkingLotDeviceLogMapper parkingLotDeviceLogMapper;
    @Autowired
    private ParkingLotDeviceVideoPileMapper parkingLotDeviceVideoPileMapper;

    /**
     * 新增log信息接口
     * @param deviceLogDtoList
     */
    public void saveLog(List<DeviceLogDto> deviceLogDtoList) {
        for (DeviceLogDto deviceLogDto : deviceLogDtoList) {
            //根据设备id查询停车场和省市信息
            VideoPileDto videoPileDto = parkingLotDeviceVideoPileMapper.getVideoPileDto(deviceLogDto.getDeviceId());
            //将这些信息与log信息整合
            deviceLogDto= FormTransfer.from2ParkingLotDeviceLog(deviceLogDto, videoPileDto);
        }
        parkingLotDeviceLogMapper.saveLog(deviceLogDtoList);
    }
}
